import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/layout.vue'
import Home from '@/views/home/index.vue'

const router = createRouter({
  history: createWebHashHistory(),
  scrollBehavior(to, from, savedPosition) {
    // 始终滚动到顶部
    return { top: 0 }
  },
  routes: [
    {
      path: '/',
      name: 'layout',
      component: Layout,
      redirect: '/home',
      children: [
        {
          path: '/home',
          name: 'home',
          component: Home
        },
        {
          path: '/category/:id',
          name: 'category',
          component: () => import('@/views/category/index.vue')
        },
        {
          path: '/category/sub/:id',
          name: 'categorySub',
          component: () => import('@/views/category/sub.vue')
        },
        {
          path: '/product/:id',
          name: 'product',
          component: () => import('@/views/goods/index.vue')
        },
        {
          path: '/cart',
          name: 'cart',
          component: () => import('@/views/cart/index.vue')
        },
      ]
    }, {
      path: '/login',
      name: 'lognin',
      component: () => import('@/views/login/index.vue')
    }
  ]
})

export default router
